<template>
<el-dialog
  :title="title"
  :visible="visible"
   width="430px" append-to-body
  @close="close" :close-on-click-modal="false">
  <el-form :model="form" :rules="rules" ref="form" :inline="false" label-width="110px">
    <el-form-item label="会议名称" prop="title">
      <el-input v-model="form.name" placeholder="请输入会议名称" ></el-input>
    </el-form-item>
    <el-form-item label="会议开始时间" prop="noticetype">
        <el-date-picker
        style="width:280px"
        v-model="value1"
        type="datetime"
        placeholder="选择日期时间">
        </el-date-picker>
    </el-form-item>
    <el-form-item label="会议结束时间">
        <el-date-picker
        style="width:280px"
        v-model="value1"
        type="datetime"
        placeholder="选择日期时间">
        </el-date-picker>
    </el-form-item>
    <el-form-item label="参会人员">
        <el-select
            style="width:280px"
            v-model="value2"
            multiple
            collapse-tags
            placeholder="请选择">
            <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
            </el-option>
        </el-select>
    </el-form-item>
  </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="visible = false">取 消</el-button>
    <el-button type="primary" @click="submit" :loading="loading">确 定</el-button>
  </span>
</el-dialog>
</template>
<script>

export default {
  props: {
    tree: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      noticeTypeList: [],
      content: '',
      visible: false,
      title: '应急监测会议',
      loading: false,
      isEdit: false,
      dic: [],
      areaList: [],
      form: {
        name: '',
        content: '',
        // 公告内容
        createid: '',
        // 创建人
        noticeid: '',
        // 公告ID
        noticetype: '',
        // 公告类型
        ordernum: '',
        // 排序
        publishid: '',
        // 发布人
        title: '',
        // 公告标题
        updateid: ''
        // 更新人
      },
      rules: {
        title: [
          { required: true, message: '请输入公告标题', trigger: 'blur' }
        ],
        noticetype: [
          { required: true, message: '请选择公告类型', trigger: 'blur' }
        ]
      }
    };
  },
  computed: {

  },
  methods: {
    //  获取公告类型
    getNoticeTypeaList() {
      const params = {
        url: `/service-base/category/list/noticeType`,
        type: 'get',
        params: {}
      };
      this.$ajax(params).then(resp => {
        console.log(`getNoticeTypeaList`, resp);
        const { data, success } = resp;
        if (success) {
          this.noticeTypeList = data.data;
        }
      });
    },
    validForm() {
      return new Promise((resolve, reject) => {
        this.$refs.form.validate((valid) => {
          if (valid) {
            resolve();
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      });
    },
    async submit() {
      await this.validForm(); // 表单校验
      console.log('校验成功');
      this.loading = true;
      const isEdit = this.isEdit;
      const params = {
        url: `/service-base/publishnotice/${isEdit ? 'update' : 'add'}`,
        type: isEdit ? 'put' : 'post',
        params: this.form
      };
      this.$ajax(params).then(resp => {
        console.log(`submit`, resp);
        this.loading = false;
        const { success } = resp;
        if (success) {
          this.$message({ message: `公告${isEdit ? '编辑' : '添加'}成功`, type: 'success' });
          this.close();
          this.$emit('refresh');
        }
      });
    },
    openDialog() {
      this.isEdit = false;
      this.visible = true;
    },
    openDialogByEdit(row) {
      console.log('row', row);
      this.isEdit = true;
      this.visible = true;
      for (const key in row) {
        this.form[key] = row[key];
      }
      this.form.content = row.contentstring;
    },
    close() {
      this.visible = false;
      for (const key in this.form) {
        this.form[key] = '';
      }
      this.form.noticestatus = 1;
      this.$refs.form.resetFields();
    }
  },
  created() {

  }
};
</script>

<style>

</style>